home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / zmodem-part1-unix.shar / vrzsz.c < prev    next >
C/C++ Source or Header  |  1993-10-23  |  4KB  |  254 lines

  1. #include "vmodem.h"
  2. #include ssdef
  3. #include tt2def
  4. #include ttdef
  5. #define SS_NORMAL SS$_NORMAL
  6.  
  7. /*  VMS structures  */
  8. /*
  9.  *    TT_INFO structures are used for passing information about
  10.  *    the terminal.  Used in GTTY and STTY calls.
  11.  */
  12. struct    tt_info    ttys, ttysnew, ttystemp;
  13.  
  14. /*
  15.  *
  16.  */
  17.  
  18. /*
  19.  * return 1 iff stdout and stderr are different devices
  20.  *  indicating this program operating with a modem on a
  21.  *  different line
  22.  */
  23. int Fromcu;        /* Were called from cu or yam */
  24. from_cu()
  25. {
  26. }
  27. cucheck()
  28. {
  29. }
  30.  
  31.  
  32.  
  33. /*
  34.  * mode(n)
  35.  *  3: save old tty stat, set raw mode with flow control
  36.  *  2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  37.  *  1: save old tty stat, set raw mode 
  38.  *  0: restore original tty mode
  39.  */
  40. mode(n)
  41. {
  42.     int    *iptr, parameters;
  43.     static savedmodes = FALSE;
  44.  
  45.     vfile("mode:%d", n);
  46.  
  47.     if (!savedmodes) {
  48.         if (gtty(&ttys) != SS$_NORMAL)
  49.             death("SETMODES:  error return from GTTY (1)");
  50.         if (gtty(&ttysnew) != SS$_NORMAL)
  51.             death("SETMODES:  error return from GTTY (2)");
  52.         savedmodes = TRUE;
  53.     }
  54.  
  55.     /*
  56.      * Set new terminal parameters.
  57.      *  Note:  there are three bytes of terminal characteristics,
  58.      *  so we should make sure the fourth byte of the integer is unchanged.
  59.      */
  60.     switch (n) {
  61.     case 1:
  62.     case 2:
  63.     case 3:
  64.         iptr    = &(ttysnew.dev_characteristics.bcharacteristics);
  65.         parameters    = *iptr;
  66.  
  67.         parameters    &= ~TT$M_ESCAPE;    /*  ESCAPE   OFF  */
  68.         parameters    &= ~TT$M_HOSTSYNC;    /*  HOSTSYNC OFF  */
  69.         parameters    |=  TT$M_NOECHO;    /*  NOECHO   ON   */
  70.         parameters    |=  TT$M_PASSALL;    /*  PASSALL  ON   */
  71.         parameters    &= ~TT$M_READSYNC;    /*  READSYNC OFF  */
  72.         parameters    &= ~TT$M_TTSYNC;    /*  TTSYNC   OFF  */
  73.         parameters    &= ~TT$M_WRAP;        /*  WRAP     OFF  */
  74.         parameters    |= TT$M_EIGHTBIT;    /*  EIGHTBIT ON   */
  75.         if (n == 3) {
  76.             parameters |= TT$M_HOSTSYNC;    /*  HOSTSYNC On  */
  77.         }
  78.         if (n == 2) {
  79.             parameters |= TT$M_TTSYNC;    /*  TTSYNC On  */
  80.         }
  81.  
  82.         *iptr        = parameters;
  83.  
  84.         if (stty(&ttysnew) != SS_NORMAL)
  85.             fatal("SETMODES:  error return from STTY");
  86.         break;
  87.     case 0:
  88.         stty(&ttys);        /*  Restore original modes  */
  89.                     /* error return to /dev/null */
  90.     break;
  91.     }
  92. }
  93.  
  94.  
  95.  
  96. /* set tty modes for vrzsz transfers */
  97. setmodes()
  98. {
  99. /*  Device characteristics for VMS  */
  100. }
  101.  
  102. fatal(msg)
  103. char *msg;
  104. {
  105.     mode(0);          /* put back normal tty modes */
  106.     printf("vrzsz:  %s\n", msg);
  107.     exit(SS_NORMAL);
  108. }
  109.  
  110. /* Call this instead if funny modes haven't been set yet */
  111. death(msg)
  112. char *msg;
  113. {
  114.     printf("vrzsz:  %s\n", msg);
  115.     exit(SS_NORMAL);
  116. }
  117.  
  118. #define LSIZE 64    /* Size of send & receive buffers */
  119. #ifdef BUFREAD
  120.  
  121. char Rxlbuf[LSIZE+1];
  122. int Rxleft=0;        /* number of characters in Rxlbuf */
  123. char *Rxcdq = Rxlbuf;    /* pointer for removing chars from Rxlbuf */
  124.  
  125. /*
  126.  * This version of readline is reasoably well suited for
  127.  * reading many characters.
  128.  *
  129.  * timeout is in tenths of seconds
  130.  */
  131.  
  132. readline(timeout)
  133. int timeout;
  134. {
  135.     register int c;
  136.     extern errno;
  137.  
  138.     if (--Rxleft>=0)
  139.         return (*Rxcdq++ & 0377);
  140. #ifdef DEBUGG
  141.     eprintf("Calling read: ");
  142. #endif
  143.     if ((c = timeout/10)<2)
  144.         c=2;
  145.  
  146.     do {
  147.         Rxleft = raw_read(LSIZE, Rxcdq=Rxlbuf, 1);
  148.     } while (Rxleft == SS$_TIMEOUT   &&   --c >= 0);
  149. #ifdef DEBUGG
  150.     eprintf("Read returned %d bytes\n", Rxleft);
  151. #endif
  152.     if (Rxleft == SS$_TIMEOUT || --Rxleft < 0) {
  153.         Rxleft = 0;
  154.         return TIMEOUT;
  155.     }
  156.     return (*Rxcdq++ & 0377);
  157. }
  158.  
  159. purgeline()
  160. {
  161.     Rxleft=0;
  162. }
  163.  
  164.  
  165. #else    /* BUFREAD */
  166.  
  167.  
  168. /* get a byte from data stream -- timeout if "dseconds" elapses */
  169. /*    NOTE, however, that this function returns an INT, not a BYTE!!!  */
  170. readline(dseconds)
  171. {
  172.     int seconds;
  173.     int ret, c;
  174.  
  175.     seconds = dseconds/10;
  176.     if (seconds < 2)
  177.         seconds = 2;
  178.     ret    = raw_read(1, &c, seconds);
  179.  
  180.     if (ret == SS$_TIMEOUT)
  181.         return(TIMEOUT);
  182.  
  183.     return(c & 0377);  /* return the char */
  184. }
  185.  
  186. purgeline()
  187. {
  188.     int c;
  189.  
  190.     do {
  191.         c = readline(1);
  192.     } while (c != TIMEOUT);
  193. }
  194. #endif
  195.  
  196.  
  197. #ifdef BUFWRITE
  198. char Txlbuf[LSIZE+1];
  199. int Txleft=LSIZE;        /* number of characters in Txlbuf */
  200. char *Txcq = Txlbuf;    /* pointer for removing chars from Rxlbuf */
  201.  
  202. sendline(c)
  203. {
  204.     if (--Txleft >= 0)
  205.         *Txcq++ = c;
  206.     else {
  207.         Txleft = 0;
  208.         flushmoc();
  209.         --Txleft;
  210.         *Txcq++ = c;
  211.     }
  212. }
  213.  
  214. flushmoc()
  215. {
  216.     register int n;
  217.  
  218.     n = LSIZE - Txleft;
  219.     Txcq=Txlbuf;  Txleft = LSIZE;
  220.     raw_wbuf(n, Txlbuf);
  221. }
  222.  
  223. /*
  224.  *  Wait for the modem line outbuffer to drain
  225.  */
  226. flushmo()
  227. {
  228.     fflush(stdout);
  229.     flushmoc();
  230. }
  231.  
  232. #else    /* BUFWRITE */
  233.  
  234. /* send a byte to data stream */
  235. sendline(data)
  236. {
  237.     char    dataout;
  238.  
  239.     dataout    = data;
  240.     raw_write(dataout);
  241.  
  242. }
  243.  
  244. flushmo() {}
  245. flushmoc() {}
  246. #endif
  247.  
  248. sendbrk()
  249. {
  250. }
  251.  
  252.  
  253. /* End of vrzsz.c */
  254.